package org.luxor.commons.workflow.entity;

import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 候选人
 *
 * @author Mr.yan  @date 2021/10/19
 */
public class Candidate {

    /**
     * 候选人
     */
    private List<String> users;

    /**
     * 候选组
     */
    private List<String> groups;

    public Candidate() {
        this.users = new ArrayList<>();
        this.groups = new ArrayList<>();
    }

    public Candidate(String userId) {
        this.addUser(userId);
    }

    public Candidate(String userId, String groupId) {
        this.addUser(userId);
        this.addGroup(groupId);
    }

    public Candidate(List<String> users, List<String> groups) {
        this.users = users == null ? new ArrayList<>() : users;
        this.groups = groups == null ? new ArrayList<>() : groups;
    }

    public List<String> getUsers() {
        return users;
    }

    public void setUsers(List<String> users) {
        this.users = users == null ? new ArrayList<>() : users;
    }

    public List<String> getGroups() {
        return groups;
    }

    public void setGroups(List<String> groups) {
        this.groups = groups == null ? new ArrayList<>() : groups;
    }

    public void addUser(String userGroup) {
        this.users.add(userGroup);
    }

    public void addGroup(String userGroup) {
        this.groups.add(userGroup);
    }

    public boolean isEmpty() {
        if (CollectionUtils.isEmpty(users)) {
            return false;
        }
        if (CollectionUtils.isEmpty(groups)) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Candidate{" +
                "users=" + Arrays.toString(this.users.toArray()) +
                ", groups=" + Arrays.toString(this.groups.toArray()) +
                '}';
    }
}
